import http from './index'
import md5 from '@/utils/md5.js'
import index from '@/common/luchApi/modules/index.js'
import find from '@/common/luchApi/modules/find.js'
/**
 * object转化成url拼接样式
 * @param obj 需要转化的参数
 */
const objToUrl = obj => {
	let arr = [];
	for (let i in obj) {
		if (obj.hasOwnProperty(i)) {
			arr.push(encodeURIComponent(i) + "=" + encodeURIComponent(obj[i]));
		}
	}
	return arr.join("&");
}
/**
 * url转化成object拼接样式
 * @param url 需要转化的参数
 */
const urlToObj = url => {
	let string = url.split('&');
	let res = {};
	for (let i = 0; i < string.length; i++) {
		let str = string[i].split('=');
		if (str[0] != '') {
			res[str[0]] = str[1];
		}
	}
	return res;
}
const API = {
	baseUrl: http.config.baseUrl,
	imgBaseUrl: http.config.imgBaseURL,
	urlH5: http.config.urlH5,
	// 接口示例 1---------------------------------------------------------------------------
	oauth: function(token) {
		return http.post(API.yygjUrl + ab_.pr('O/oauth'), JSON.stringify([token]));
	},
	

	// -------------------引入分割的模块---------------------
	...index,
	...find,//发现模块
	// -------------------引入分割的模块结束---------------------
	
	// 接口示例 2---------------------------------------------------------------------------
	getWanJiaToken() {
		return http.post(API.wanjiaURL, {
			method: "token.gettoken",
			appid: "YY_wanjia",
			sign: "SDDFJSDMWSDFJ"
		})
	},
	// 接口示例 3---------------------------------------------------------------------------
	refreshToken: function(userId) {
		return http.post('user/refreshToken',  objToUrl({
			userId: userId
		}));
	},
	

	// 公用接口-----------------------------------------------------------------------------
	/**
	 * 功能获取用户信息
	 * @param {null} 无传参,通过用户token进行后台解析  
	 */ 
	queryUserInfo(){
		return http.get("user/queryUser")
	},
	// 通过token获取用户信息
	userGetUserByToken() {
		return http.get("user/getUserByToken")
	}
}

export default API
